<template>
  <div class="monitoring">
    <div class="left">
      <div class="top">
        <div class="title">揽收监控</div>
        <div class="text">
          <span class="f20">本月收件</span>
          <span class="f16"
            >（统计时间截止：{{ addresseeData.statisticalTime }}）</span
          >
        </div>
        <div class="statistic flex">
          <div>
            <div class="text">合计收件</div>
            <div
              v-if="addresseeNumber && addresseeNumber.totalReceipts"
              class="number"
            >
              <div
                v-for="(item, index) in addresseeNumber.totalReceipts[0]"
                :key="index"
              >
                {{ item }}
              </div>
              <div class="dot">·</div>
              <div v-for="(item, index) in addresseeNumber.totalReceipts[1]">
                {{ item }}
              </div>
              <div class="unit">万</div>
            </div>
          </div>
          <div>
            <div class="text">日均收件</div>
            <div
              v-if="addresseeNumber && addresseeNumber.dailyAverageReceipt"
              class="number"
            >
              <div
                v-for="(item, index) in addresseeNumber.dailyAverageReceipt[0]"
                :key="index"
              >
                {{ item }}
              </div>
              <div class="dot">·</div>
              <div
                v-for="(item, index) in addresseeNumber.dailyAverageReceipt[1]"
              >
                {{ item }}
              </div>
              <div class="unit">万</div>
            </div>
          </div>
          <div>
            <div class="text">昨日收件</div>
            <div
              v-if="addresseeNumber && addresseeNumber.receivedYesterday"
              class="number"
            >
              <div
                v-for="(item, index) in addresseeNumber.receivedYesterday[0]"
                :key="index"
              >
                {{ item }}
              </div>
              <div class="dot">·</div>
              <div
                v-for="(item, index) in addresseeNumber.receivedYesterday[1]"
              >
                {{ item }}
              </div>
              <div class="unit">万</div>
            </div>
          </div>
        </div>
        <div class="charts">
          <Annulus
            :percentage="addresseeData.businessVolume"
            :color="`#2087D0`"
            :strokeWidth="16"
            text="目标"
          />
          <div class="target">
            <div>
              业务量<span>{{ addresseeData.businessVolume }}</span>
            </div>
            <div>
              目标{{ addresseeData.dailyTarget }}/日均{{
                addresseeData.dailyAverageReceipt
              }}
            </div>
            <el-date-picker
              v-model="date"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>
        </div>
      </div>
      <div class="bottom flex">
        <div class="order">
          <div class="title">
            今日订单<span>（实时数据，待揽收为近三天）</span>
          </div>
          <div class="item">
            <div class="name">订单量</div>
            <div v-if="orderTodayData" class="number">
              <div
                v-for="(item, index) in orderTodayNumber.orderQuantity"
                :key="index"
              >
                {{ item }}
              </div>
              <div class="unit">件</div>
              <!-- <div class="rate">↓-76%</div> -->
            </div>
          </div>
          <div class="item">
            <div class="name">收件量</div>
            <div class="number">
              <div
                v-for="(item, index) in orderTodayNumber.receivedQuantity"
                :key="index"
              >
                {{ item }}
              </div>
              <div class="unit">件</div>
              <!-- <div class="rate">↓-76%</div> -->
            </div>
          </div>
          <div class="item">
            <div class="name">未收件量</div>
            <div class="number">
              <div
                v-for="(item, index) in orderTodayNumber.unreceivedQuantity"
                :key="index"
              >
                {{ item }}
              </div>
              <div class="unit">件</div>
              <!-- <div class="rate">↓-76%</div> -->
            </div>
          </div>
        </div>
        <div class="customer">
          <div class="title flex">
            <div class="name">客户</div>
            <SelectNetwork />
          </div>
          <el-table
            height="350px"
            border
            tooltip-effect="dark"
            :data="tableData"
          >
            <el-table-column prop="name" label="名称"> </el-table-column>
            <el-table-column prop="orderCount" label="订单量" sortable>
            </el-table-column>
            <el-table-column prop="receivedQuantity" label="收件量" sortable>
            </el-table-column>
            <el-table-column prop="pendingCollection" label="待揽收" sortable>
            </el-table-column>
            <el-table-column prop="declineRate" label="订单量下降比率" sortable>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="forecast">
        <div class="title">预测单量</div>
        <div class="road">
          <div class="name">
            <div class="start">辽宁盘锦转运中心</div>
            <div class="end">至本网点</div>
          </div>
          <div class="icon">
            <i class="el-icon-sort"></i>
          </div>
        </div>
        <div class="modal flex">
          <div class="today">
            <div class="title">
              今日二派件量预测<span>4-25 05:30至04-25 11:30</span>
            </div>
            <div class="flex">
              <div class="chart">
                <Annulus
                  :percentage="0"
                  :color="`#2087D0`"
                  :width="108"
                  :strokeWidth="10"
                />
                <div class="remark">09:00平均预测准 确率（近7天）</div>
              </div>
              <div class="analyse">
                <div class="item">
                  <div class="name flex">
                    <div>预测总件量</div>
                    <div class="total">622票</div>
                  </div>
                  <div class="flex">
                    <div style="width: 200px">
                      <Score
                        :percentage="50"
                        :color="`#2087D0`"
                        :showText="false"
                      />
                    </div>
                    <div class="rate">↓52.1%</div>
                  </div>
                </div>
                <div class="item">
                  <div class="name flex">
                    <div>预测总件量</div>
                    <div class="total">622票</div>
                  </div>
                  <div class="flex">
                    <div style="width: 200px">
                      <Score
                        :percentage="50"
                        :color="`#2087D0`"
                        :showText="false"
                      />
                    </div>
                    <div class="rate">↓52.1%</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="tomorrow">
            <div class="title">
              明日一派件量预测<span>4-25 05:30至04-25 11:30</span>
            </div>
            <div class="flex">
              <div class="chart">
                <Annulus
                  :percentage="0"
                  :color="`#2087D0`"
                  :width="108"
                  :strokeWidth="10"
                />
                <div class="remark">09:00平均预测准 确率（近7天）</div>
              </div>
              <div class="analyse">
                <div class="item">
                  <div class="name flex">
                    <div>预测总件量</div>
                    <div class="total">622票</div>
                  </div>
                  <div class="flex">
                    <div style="width: 200px">
                      <Score
                        :percentage="50"
                        :color="`#F4B259`"
                        :showText="false"
                      />
                    </div>
                    <div class="rate">↓52.1%</div>
                  </div>
                </div>
                <div class="item">
                  <div class="name flex">
                    <div>预测总件量</div>
                    <div class="total">622票</div>
                  </div>
                  <div class="flex">
                    <div style="width: 200px">
                      <Score
                        :percentage="50"
                        :color="`#F4B259`"
                        :showText="false"
                      />
                    </div>
                    <div class="rate">↓52.1%</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="bottom flex">
        <div class="chart">
          <BrokenColumn :optionData="SevenDayFinedata" />
        </div>
        <div class="chart">
          <BrokenColumn :optionData="SevenDayFinedata" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getCustom, getAddressee, getOrderToday } from "@/api/collect";
import { getSevenDayFineApi } from "@/api/QualityStatement";

export default {
  name: "Monitoring",
  data() {
    return {
      date: null,
      options: null,
      value: null,
      orderTodayData: {},
      orderTodayNumber: {},
      addresseeData: {},
      addresseeNumber: {},
      tableData: null,
      SevenDayFinedata: null,
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.getCustomData();
      this.getAddresseeData();
      this.getOrderTodayData();
      this.getSevenDayFineData();
    },
    async getSevenDayFineData() {
      const res = await getSevenDayFineApi();
      console.log("近七天罚款", res);
      this.SevenDayFinedata = res.data;
    },
    getCustomData() {
      getCustom().then((res) => {
        this.tableData = res.data;
      });
    },
    getAddresseeData() {
      getAddressee().then((res) => {
        this.addresseeData = res.data;
        this.addresseeNumber.totalReceipts = this.formatNumberDot(
          res.data.totalReceipts
        );
        this.addresseeNumber.dailyAverageReceipt = this.formatNumberDot(
          res.data.dailyAverageReceipt
        );
        this.addresseeNumber.receivedYesterday = this.formatNumberDot(
          res.data.receivedYesterday
        );
      });
    },
    getOrderTodayData() {
      getOrderToday().then((res) => {
        this.orderTodayData = res.data;
        this.orderTodayNumber.orderQuantity = this.formatNumber(
          res.data.orderQuantity
        );
        this.orderTodayNumber.receivedQuantity = this.formatNumber(
          res.data.receivedQuantity
        );
        this.orderTodayNumber.unreceivedQuantity = this.formatNumber(
          res.data.unreceivedQuantity
        );
      });
    },
    formatNumberDot(num) {
      let dotBefore = [];
      let dotAfter = [];
      let integerPart = Math.floor(num / 10000);
      let decimalPart = ((num % 10000) / 10000).toFixed(2).substring(2);
      let integerStr = integerPart.toString();
      for (let char of integerStr) {
        dotBefore.push(char);
      }
      for (let char of decimalPart) {
        dotAfter.push(char);
      }
      return [dotBefore, dotAfter];
    },
    formatNumber(num) {
      let nums = [];
      let strs = num.toString();
      for (let char of strs) {
        nums.push(char);
      }
      return nums;
    },
  },
};
</script>
<style lang="scss" scoped>
.monitoring {
  padding: 30px 10px 30px 30px;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  background-color: #f5f5f5;

  .flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .el-progress {
    &::v-deep .el-progress__text {
      font-size: 24px !important;
    }
  }

  .top,
  .order,
  .customer,
  .right .forecast,
  .bottom > div {
    background: #ffffff;
    box-shadow: 0px 2px 2px 0px rgba(113, 121, 144, 0.06);
    border-radius: 8px;
  }

  .title {
    font-weight: 500;
    font-size: 20px;
    color: #333333;
  }

  .left {
    width: 852px;

    .top {
      padding: 24px;
      height: 444px;

      .text {
        margin-top: 28px;

        .f20 {
          font-size: 20px;
        }

        .f16 {
          font-size: 16px;
          color: #666;
        }
      }

      .statistic {
        justify-content: space-around;

        .text {
          font-size: 18px;
          color: #2087d0;
        }

        .number {
          margin-top: 20px;
          display: flex;

          & > div + div {
            margin-left: 2px;
          }

          div {
            width: 52px;
            height: 60px;
            line-height: 60px;
            background: #2087d0;
            border-radius: 2px;
            border: 1px solid #2087d0;
            font-size: 42px;
            font-weight: bold;
            color: #fff;
            text-align: center;
          }

          .dot {
            width: 20px;
            background-color: #fff;
            color: #2087d0;
            border: none;
            font-size: 24px;
            line-height: 80px;
          }

          .unit {
            width: 18px;
            line-height: 80px;
            font-weight: normal;
            border: none;
            font-size: 18px;
            background-color: #fff;
            color: #333333;
          }
        }
      }

      .charts {
        margin-top: 40px;
        text-align: center;
        display: flex;
        justify-content: center;

        .target {
          margin-left: 30px;
          display: flex;
          flex-direction: column;
          justify-content: space-around;
          text-align: left;
          font-weight: 400;
          font-size: 18px;
          color: #666666;

          span {
            margin-left: 20px;
            color: #333;
          }
        }
      }
    }

    .bottom {
      margin-top: 20px;
      height: 430px;

      & > div {
        padding: 24px;
        height: 100%;
      }

      .order {
        width: 356px;

        .title {
          span {
            font-weight: 400;
            font-size: 16px;
            color: #666666;
          }
        }

        .item {
          padding: 30px 0;

          .name {
            font-weight: 400;
            color: #666;
          }

          .number {
            margin-top: 16px;
            display: flex;

            & > div + div {
              margin-left: 4px;
            }

            div {
              width: 30px;
              height: 30px;
              line-height: 30px;
              text-align: center;
              background: linear-gradient(
                0deg,
                rgba(32, 135, 208),
                rgba(155, 203, 235)
              );
              border-radius: 4px;
              font-weight: 400;
              font-size: 24px;
              color: #ffffff;
            }

            .unit,
            .rate {
              background-color: #fff;
              border-radius: 0;
              font-size: 16px;
              text-align: left;
              line-height: 40px;
              background: none;
            }

            .unit {
              width: 24px;
              color: #666;
            }

            .rate {
              color: #f45959;
            }
          }
        }

        .item + .item {
          border-top: 1px solid #ebecee;
        }
      }

      .customer {
        width: 476px;

        .title {
          margin-bottom: 10px;
        }
      }
    }
  }

  .right {
    width: 988px;

    .forecast {
      padding: 24px;
      height: 416px;

      .road {
        margin-top: 16px;
        display: flex;

        .name {
          font-size: 18px;
          height: 64px;
          line-height: 32px;

          .end {
            color: #999;
          }
        }

        .icon {
          margin-left: 10px;
          height: 64px;
          line-height: 64px;
          font-size: 24px;
          color: #999;
        }
      }

      .modal {
        margin-top: 16px;

        .tomorrow {
          .el-progress {
            &::v-deep .el-progress__text {
              color: #f4b259 !important;
            }
          }
        }

        & > div {
          padding: 24px;
          width: 460px;
          height: 250px;
          background: #fafafa;
          border-radius: 8px;
          border: 1px solid #ebecee;
        }

        .title {
          span {
            margin-left: 16px;
            font-weight: 400;
            font-size: 16px;
            color: #999999;
          }
        }

        .flex {
          .chart {
            margin-top: 16px;
            width: 124px;
            text-align: center;

            .remark {
              margin-top: 10px;
              font-weight: 400;
              font-size: 16px;
              color: #666666;
            }
          }

          .analyse {
            width: 260px;

            .item + .item {
              margin-top: 30px;
            }

            .item {
              font-weight: 400;
              font-size: 16px;
              color: #666666;

              .name {
                margin-bottom: 6px;

                .total {
                  color: #333;
                }
              }

              .rate {
                color: #f45959;
              }
            }
          }
        }
      }
    }

    .bottom {
      margin-top: 20px;
      height: 458px;

      .chart {
        width: 484px;
        height: 100%;
      }
    }
  }
}
</style>
